package com.gitee.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.mapper.CookbookFoodMapper;
import com.gitee.pojo.CookbookFood;
import com.gitee.service.ICookbookFoodService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
public class CookbookFoodServiceImpl extends ServiceImpl<CookbookFoodMapper, CookbookFood> implements ICookbookFoodService {


    /**
     * 根据cookbookId删除关联菜品
     *
     * @param cookbookId
     * @return
     */
    @Transactional
    @Override
    public Boolean removeByCookbookId(Integer cookbookId) {
        LambdaUpdateWrapper<CookbookFood> luq = new UpdateWrapper<CookbookFood>().lambda().eq(CookbookFood::getCookbookId, cookbookId);
        return super.remove(luq);
    }

    /**
     * 根据cookbookIds删除关联菜品
     *
     * @param cookbookIds
     * @return
     */
    @Transactional
    @Override
    public Boolean removeByCookbookIds(Integer[] cookbookIds) {
        LambdaUpdateWrapper<CookbookFood> luq = new UpdateWrapper<CookbookFood>().lambda().in(CookbookFood::getCookbookId, Arrays.asList(cookbookIds));
        return super.remove(luq);
    }

    /**
     * 根据foodId删除关联菜品
     *
     * @param foodId
     * @return
     */
    @Transactional
    @Override
    public Boolean removeByFoodId(Integer foodId) {
        LambdaUpdateWrapper<CookbookFood> luq = new UpdateWrapper<CookbookFood>().lambda().eq(CookbookFood::getFoodId, foodId);
        return super.remove(luq);
    }

    /**
     * 根据foodIds删除关联菜品
     *
     * @param foodIds
     * @return
     */
    @Transactional
    @Override
    public Boolean removeByFoodIds(Integer[] foodIds) {
        LambdaUpdateWrapper<CookbookFood> luq = new UpdateWrapper<CookbookFood>().lambda().in(CookbookFood::getFoodId, foodIds);
        return super.remove(luq);
    }
}
